package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.freshfresh.activity.R;
import com.freshfresh.utils.ImageLoadOptions;
import com.nostra13.universalimageloader.core.ImageLoader;


public class FenleiAdapter extends BaseAdapter {
	List<Map<String,Object>> apk_list;
	LayoutInflater inflater;

	public FenleiAdapter(Context context, List<Map<String,Object>> apk_list) {
		this.apk_list = apk_list;
		this.inflater = LayoutInflater.from(context);
	}
	public void onDateChange(List<Map<String,Object>> apk_list) {
		this.apk_list = apk_list;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return apk_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return apk_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Map<String,Object> entity = apk_list.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.it_classification_item, null);
			holder.iv_classification_icon = (ImageView) convertView
					.findViewById(R.id.iv_classification_icon);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		if(entity.get("appimage")!=null){
			ImageLoader.getInstance().displayImage(entity.get("appimage").toString(), holder.iv_classification_icon, ImageLoadOptions.getOptions(0));
			}
		
		return convertView;
	}

	class ViewHolder {
		ImageView iv_classification_icon;//图片
	}
}
